bitkeeper revision 1.1229 (42180985F67QALsnFjovJHWiIDEz_A)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 20 Feb 2005 03:52:37 +0000 (03:52 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 20 Feb 2005 03:52:37 +0000 (03:52 +0000)
Fix return-code checking in tools.
Signed-off-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_plan9_build.c
tools/libxc/xc_private.c
tools/python/xen/lowlevel/xc/xc.c
tools/xentrace/xentrace.c

index 0394938c1749638347605cb0dbeac8872d80e2e4..417cc780327ab6b73885e9169f10c6c97c55746f 100755 (executable)
@@ -58,33 +58,6 @@ memcpy_toguest(int xc_handle, u32 dom, void *v, int size,
        return ret;
 }
 
-/* this is a function which can go away. It dumps a hunk of 
- * guest pages to a file (/tmp/dumpit); handy for debugging
- * your image builder. 
- * Xen guys, nuke this if you wish.
- */
-void
-dumpit(int xc_handle, u32 dom,
-       int start_page, int tot, unsigned long *page_array)
-{
-       int i, ofd;
-       unsigned char *vaddr;
-
-       ofd = open("/tmp/dumpit", O_RDWR);
-       for (i = start_page; i < tot; i++) {
-               vaddr = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
-                                            PROT_READ | PROT_WRITE,
-                                            page_array[i]);
-               if (!vaddr) {
-                       fprintf(stderr, "Page %d\n", i);
-                       perror("shit");
-                       read(0, &i, 1);
-                       return;
-               }
-               write(ofd, vaddr, 4096);
-               munmap(vaddr, PAGE_SIZE);
-       }
-}
 int
 blah(char *b)
 {
index 65aa1085e0b8a77e7b68103e1be5e89211e1de95..37342ac8378d972f06e8feb832ae69a6b670f1f5 100644 (file)
@@ -276,12 +276,14 @@ unsigned long xc_get_filesz(int fd)
     unsigned long sz;
 
     lseek(fd, 0, SEEK_SET);
-    read(fd, &sig, sizeof(sig));
+    if ( read(fd, &sig, sizeof(sig)) != sizeof(sig) )
+        return 0;
     sz = lseek(fd, 0, SEEK_END);
     if ( sig == 0x8b1f ) /* GZIP signature? */
     {
         lseek(fd, -4, SEEK_END);
-        read(fd, &_sz, 4);
+        if ( read(fd, &_sz, 4) != 4 )
+            return 0;
         sz = _sz;
     }
     lseek(fd, 0, SEEK_SET);
@@ -302,7 +304,11 @@ char *xc_read_kernel_image(const char *filename, unsigned long *size)
         goto out;
     }
 
-    *size = xc_get_filesz(kernel_fd);
+    if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
+    {
+        PERROR("Could not read kernel image");
+        goto out;
+    }
 
     if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
     {
index 543a2cd38042009d4827de12e0c90754e8ebfff1..2e425d488705682050f5845f551fc09560a106fe 100644 (file)
@@ -430,11 +430,9 @@ static PyObject *pyxc_vmx_build(PyObject *self,
     printf ("numItems: %d\n", numItems);
     mem_map.nr_map = numItems;
    
-
     /* should raise an error here. */
     if (numItems < 0) return NULL; /* Not a list */
 
-
     /* iterate over items of the list, grabbing ranges and parsing them */
     for (i = 1; i <= numItems; i++) {  // skip over "memmap"
            PyObject *item, *f1, *f2, *f3, *f4;
@@ -461,8 +459,10 @@ static PyObject *pyxc_vmx_build(PyObject *self,
            sf2 = PyString_AsString(f2);
            lf3 = PyLong_AsLong(f3);
            lf4 = PyLong_AsLong(f4);
-           sscanf(sf1, "%lx", &lf1);
-           sscanf(sf2, "%lx", &lf2);
+           if ( sscanf(sf1, "%lx", &lf1) != 1 )
+                return NULL;
+           if ( sscanf(sf2, "%lx", &lf2) != 1 )
+                return NULL;
 
             mem_map.map[i-1].addr = lf1;
             mem_map.map[i-1].size = lf2 - lf1;
index 351ecd71a8563a5301724b6af27eb6cd4651815b..2eaa1a1c25a255ec93c6b0e730b82c134e91835b 100644 (file)
@@ -77,8 +77,14 @@ struct timespec millis_to_timespec(unsigned long millis)
  */
 void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
 {
-    fwrite(&cpu, sizeof(cpu), 1, out);
-    fwrite(rec, sizeof(*rec), 1, out);
+    size_t written = 0;
+    written += fwrite(&cpu, sizeof(cpu), 1, out);
+    written += fwrite(rec, sizeof(*rec), 1, out);
+    if ( written != 2 )
+    {
+        PERROR("Failed to write trace record");
+        exit(EXIT_FAILURE);
+    }
 }
 
 /**